/** CS2340 40 Jiggawatt Hard Driver Project
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 */

// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
package edu.gatech.jiggawatt.office.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */
public class Database implements Serializable {
	
	/**
	 * Stores users
	 */
	private List<User> users; // $codepro.audit.disable variableShouldBeFinal
	
	/**
	 * Constructor for Database.
	 */
	public Database() {
		users = new ArrayList<User>();
	}
	
	/**
	 * Method addUser.
	 * @param user User
	 */
	public void addUser(User user) {
		users.add(user);
	}
	
	/**
	 * Method getUser.
	 * @param id String
	 * @return User
	 */
	public User getUser(String id) {
		for (User e : users) {
			if (e.getId().equals(id)) {
				return e;
			}
		}
		return null;
	}
	
	/**
	 * Method getUserList.
	 * @return List<User>
	 */
	public List<User> getUserList() {
		return users;
	}
	
	/**
	 * Method getPatient.
	 * @param fullName String
	 * @return Patient
	 */
	public Patient getPatient(String fullName) {
		for (User e : users) {
			if (e.getFullName().equals(fullName) && e.getUserType() == 1) {
				return (Patient) e;
			}
		}
		return null;
	}
	
	/**
	 * Method removeUser.
	 * @param id String
	 * @return boolean
	 */
	public boolean removeUser(String id) { // $codepro.audit.disable booleanMethodNamingConvention
		for (User e : users) {
			if (e.getId().equals(id)) {
				users.remove(e);
				return true;
			}
		}
		return false;
	}
}
